import JSZip from 'jszip';

// 压缩 Base64 字符串
export async function compressBase64(base64String:string) {
  // 将 Base64 字符串解码为二进制数据
  const binaryString = atob(base64String);
  const uint8Array = new Uint8Array(binaryString.length);
  for (let i = 0; i < binaryString.length; i++) {
    uint8Array[i] = binaryString.charCodeAt(i);
  }

  const zip = new JSZip();
  zip.file('data', uint8Array);

  // 生成压缩的 Base64 字符串
  const compressedBase64 = await zip.generateAsync({ type: 'base64' });
  return compressedBase64;
}

// 解压缩 Base64 字符串 
export async function decompressBase64(compressedBase64:string) {
  const zip = new JSZip();
  const zipData = await zip.loadAsync(compressedBase64, { base64: true });
  const decompressedData = await zipData.file('data').async('text');
  return btoa(decompressedData);
}


